<?php
define('FPDF_FONTPATH', 'font/');
require('./font/fpdf.php');
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{
  $pdf=new FPDF('P','mm','A4');   //Create new pdf file
  $pdf->Open();     //Open file
  $pdf->SetAutoPageBreak(false);  //Disable automatic page break
  $pdf->AddPage();  //Add first page

  $i         = 0; 
  $rowHeight = 6;
  $yAxis     = 19;

  $yAxis = $yAxis + $rowHeight;
  
  pageHeader();
  pageContain();
  pageFooterlast();
  

   $selectFP = "SELECT finalProcessId,finalProcessName
                 FROM finalprocess
                ORDER BY finalProcessName";
   $selectFPResult = mysql_query($selectFP);
   while($fpRow = mysql_fetch_array($selectFPResult))
   {
     $finalProcessId   = $fpRow['finalProcessId'];
     $finalProcessName = $fpRow['finalProcessName'];
   }
  
  
  $selectincomingRegister = "SELECT outgoingMasterId,outgoingmaster.incomingId,outChallenNo,partyName,
	                                    DATE_FORMAT(incoming.IncomingDate,'%d-%m-%Y')AS IncomingDate,incomingQuantity,challan,incomingWeight,
	                                    materialName,hardne,dispatchQuantity,dispatchWeight
	                               FROM outgoingmaster
	                               JOIN incoming ON outgoingmaster.incomingId = incoming.incomingId
	                               LEFT JOIN party ON party.partyId = incoming.partyId
	                               LEFT JOIN material ON material.materialId = incoming.materialId
	                              WHERE (outQuantity > '0' OR outWeight > '0')
	                                AND billGenerated = '0'
	                                AND outgoingmaster.incomingId = ".$_REQUEST['incomingId'];
	  $selectincomingRegisterRes = mysql_query($selectincomingRegister);
	  while($incomingRow = mysql_fetch_array($selectincomingRegisterRes))
	  {
	  	$outgoingMasterId  = $incomingRow['outgoingMasterId'];
	  	$incomingId        = $incomingRow['incomingId'];
	  	$outChallenNo      = $incomingRow['outChallenNo'];
	  	$partyName         = $incomingRow['partyName'];
	  	$IncomingDate      = $incomingRow['IncomingDate'];
	  	$qty               = $incomingRow['incomingQuantity'];
	  	$challan           = $incomingRow['challan'];
	  	$weight            = $incomingRow['incomingWeight'];
	  	$material          = $incomingRow['materialName'];
	  	$hardne            = $incomingRow['hardne'];
	  	$outQuantity       = $incomingRow['dispatchQuantity'];
	  	$outWeight         = $incomingRow['dispatchWeight'];
	  	$rowCount          = $i;
	  	$i++; 
	  }
    
}
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Times','B',13);
  $pdf->SetXY(17,58);
  $pdf->Cell(104, 5, $partyName,0,0,'L');
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Times','',12);
  $pdf->SetXY(5,95);
  $pdf->Cell(12, 10, $outChallenNo,1,0,'C');
  
  $pdf->SetXY(17,95);
  $pdf->Cell(23, 10, $IncomingDate,1,0,'C');
  
  $pdf->SetXY(40,95);
  $pdf->Cell(15,10, $challan,1,0,'C');
  
  $pdf->SetXY(55,95);
  $pdf->Cell(30, 10, $material,1,0,'C');
  
  $pdf->SetXY(85,95);
  $pdf->Cell(35,10, $finalProcessName,1,0,'C');
  
  $pdf->SetXY(120,95);
  $pdf->Cell(20,10, $outWeight,1,0,'C');
  
  $pdf->SetXY(140,95);
  $pdf->Cell(15,10, $outQuantity,1,0,'C');
  
  
  $pdf->SetXY(10,65);
  $pdf->Cell(15,10, $incomingId,1,0,'C');

  $pdf->Output();

function pageHeader()
{
  global $pdf;
  
  $pdf->Image('./logo/logo2.jpg',5,0,200,40);
  $pdf->Image('./logo/logo3.jpg',7,40,203,10);
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Times','',35);
  $pdf->SetXY(5,52);
  $pdf->Cell(200, 175, '', 1, 0, 'C');

  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', 'B', 12);
  $pdf->SetXY(5,58);
  $pdf->Cell(200, 6, 'Ms. :',   0, 0, 'L', 0);
  $pdf->Line(16,63,120,63);
  $pdf->SetXY(125,58);
  $pdf->Cell(80, 6, 'Memo No. :',  0, 0, 'L', 0);
  $pdf->Line(149,63,200,63);
  $pdf->SetXY(125,68);
  $pdf->Cell(80, 6, 'Memo Date. :',  0, 0, 'L', 0);
  $pdf->Line(155,73,200,73);
}

function pageContain()
{
  global $pdf;
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', 'B', 12);
  $pdf->SetXY(5,80);
  $pdf->Cell(35, 15, '',   1, 0, 'R', 0);
  $pdf->SetXY(12,78);
  $pdf->Cell(20, 15, 'Challan',   0, 0, 'C', 0);
  $pdf->SetXY(13,83);
  $pdf->Cell(20, 15, 'Date : No.',   0, 0, 'C', 0);
  
  
  $pdf->SetXY(40,80);
  $pdf->Cell(15, 15, '',   1, 0, 'C', 0);
  $pdf->SetFont('Arial', 'B', 8);
  $pdf->SetXY(40,80);
  $pdf->Cell(15, 5, 'Your ',   0, 0, 'C', 0);
  $pdf->SetXY(40,85);
  $pdf->Cell(15, 5, 'Challan ',   0, 0, 'C', 0);
  $pdf->SetXY(40,90);
  $pdf->Cell(15, 5, 'NO',   0, 0, 'C', 0);
  
  
  $pdf->SetFont('Arial', 'B', 12);
  $pdf->SetXY(55,80);
  $pdf->Cell(30, 15, 'Part Name',   1, 0, 'C', 0);
  $pdf->Cell(35, 15, 'Process Name',   1, 0, 'C', 0);
  $pdf->Cell(20, 15, 'Weight',  1, 0, 'C', 0);
  $pdf->Cell(15, 15, 'Pcs.',  1, 0, 'C', 0);

  $pdf->SetXY(155,80);
  $pdf->Cell(25, 15, '',   1, 0, 'C', 0);
  $pdf->SetXY(155,78);
  $pdf->Cell(25, 15, 'Rate',   0, 0, 'C', 0);
  $pdf->SetXY(155,82);
  $pdf->Cell(25, 15, 'Kg. Pcs.',   0, 0, 'C', 0);
  
  $pdf->SetXY(180,80);
  $pdf->Cell(25, 15, 'Amount', 1, 0, 'C', 0);
  
  $pdf->Line(17,95,17,227);
  $pdf->Line(40,95,40,227);
  $pdf->Line(55,95,55,227);
  $pdf->Line(85,95,85,227);
  $pdf->Line(120,95,120,227);
  $pdf->Line(140,95,140,227);
  $pdf->Line(155,95,155,227);
  $pdf->Line(180,95,180,227);
  
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', '', 15);
  $pdf->SetXY(5,228);
  $pdf->Cell(115, 32, '', 1, 0, 'L', 0);
  $pdf->SetXY(5,228);
  $pdf->Cell(115, 10, '  Rs. In Words', 1, 0, 'L', 0);
  
  $pdf->SetFont('Arial', 'B', 12);
  $pdf->SetXY(5,239);
  $pdf->Cell(115, 6, '  Terms & Condition', 0, 0, 'L', 0);
  
  $pdf->SetFont('Arial', '', 10);
  $pdf->SetXY(5,244);
  $pdf->Cell(115, 6, '  1. E.&.O.E.', 0, 0, 'L', 0);
  $pdf->SetXY(5,249);
  $pdf->Cell(115, 6, '  2. Interrest @ 18% Will Be charged On Amount Overdue After 45 Day .', 0, 0, 'L', 0);
  $pdf->SetXY(5,254);
  $pdf->Cell(115, 6, '  3. Subjects To Rajkot Jurisdiction.', 0, 0, 'L', 0);
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', '', 12);
  $pdf->SetXY(121,228);
  $pdf->Cell(59, 32, '', 1, 0, 'L', 0);
  $pdf->SetXY(121,228);
  $pdf->Cell(59, 10, 'Sub Totol', 0, 0, 'L', 0);
  $pdf->SetXY(121,235);
  $pdf->Cell(59, 10, '+ Services Tax @', 0, 0, 'L', 0);
  $pdf->SetXY(121,241);
  $pdf->Cell(59, 10, '+ Edu.Cess @', 0, 0, 'L', 0);
  
  $pdf->SetFont('Arial', 'B', 15);
  $pdf->SetXY(121,250);
  $pdf->Cell(59, 10, '   Net Total', 1, 0, 'L', 0);
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetXY(181,228);
  $pdf->Cell(24, 32, '', 1, 0, 'L', 0);
  $pdf->SetXY(181,250);
  $pdf->Cell(24, 10, '', 1, 0, 'L', 0);
}

function pageFooterlast()
{
  global $pdf;
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', '', 12);
  $pdf->SetXY(5,261);
  $pdf->Cell(200, 30, '', 1, 0, 'L', 0);
  
  $pdf->SetXY(5,175);
  $pdf->Cell(1, 180, '  I.T.PAN NO. : ABHFS 9017 R', 0, 0, 'L', 0);
  $pdf->SetXY(5,182);
  $pdf->Cell(1, 180, '  GST TIN :        24092501705  Dt.  14/08/2007', 0, 0, 'L', 0);
  $pdf->SetXY(5,188);
  $pdf->Cell(1, 180, '  GST TIN :        24592501705  Dt.  14/08/2007', 0, 0, 'L', 0);
  $pdf->SetXY(5,194);
  $pdf->Cell(1, 180, '  SERVICES TAX N. :ABHFS 9017 R ST001', 0, 0, 'L', 0);
  $pdf->SetXY(140,281);
  $pdf->Cell(44, 10, 'AuthoRised  Signatory', 0, 0, 'L', 0);
  $pdf->SetXY(113,261);
  $pdf->Cell(11, 10, '  For,', 0, 0, 'L', 0);
  $pdf->SetTextColor(230,0,0);
  $pdf->SetFont('Arial', 'B', 13);
  $pdf->SetXY(123,261);
  $pdf->Cell(11, 10, '  Shakti Heat-Treaters & Engineers', 0, 0, 'L', 0);
  
}

?>